const connection = require('../app/batabase');

class labelService {
    async create (name) {
        const statement = `INSERT INTO label (name) VALUE (?);`;
        const [result] = await connection.execute(statement, [name]);
        return result;
    }

    async isExistLabel(name) {
        const statement = `SELECT * FROM label WHERE name = ?;`;
        const [result] = await connection.execute(statement, [name]);
        // console.log(result);
        return result[0];
    }

    /**
     * 
     * @param {参数一} offset：偏移位，从哪个地方开始查起 
     * @param {参数二} size ：一次查询的数量
     * @returns：返回查询到的内容
     */
    async getLabels (offset, size) {
        const statement = `SELECT * FROM label LIMIT ?, ?;`;
        const [result] = await connection.execute(statement, [offset, size]);
        return result;
    }

    async deleteLabels (momentId) {
        const statement = `DELETE FROM moment_label WHERE moment_id = ?;`;
        const result = await connection.execute(statement, [momentId]);
        return result[0];
    }
}

module.exports = new labelService();